<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>

<%@ include file="/mt/common/pickerPopupHelper.jsp" %>

<script language="JavaScript">

function setParentCategory(ids,names) {
  if(ids.length>=1 && names.length>=1) {
    document.epPortletEntityForm.parentCategoryPath.value = names[0];
    document.epPortletEntityForm.categoryPath.value = names[0];
  }
}

function doCategoryPopup(form) {
  doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>','setParentCategory',317,
    form.parentCategoryPath.value,null,null,true,true,false,null,null,0,false);
}

//
//
//
function doCancel() {
  var action;
  <c:if test="${epPortletEntityForm.map.id != ''}">
    action = '<c:url value="/ep/portletEntityView.do"/>';
    if (action.indexOf("?") == -1) {
      action += "?";
    }
    action += "programId=" + document.epPortletEntityForm.programId.value;
  </c:if>
  <c:if test="${epPortletEntityForm.map.id == ''}">
    action = '<c:url value="/ep/portletEntityList.do"/>';
    if (action.indexOf("?") == -1) {
      action += "?";
    }
    action += "portletId=" + '<c:out value="${epPortletEntityForm.map.portletName}"/>';
    action += "&portletAppId=" + '<c:out value="${epPortletEntityForm.map.portletAppId}"/>';
    action += "&serverId=" + <c:out value="${epPortletEntityForm.map.serverId}"/>;
  </c:if>
  document.epPortletEntityForm.action = action;
  document.epPortletEntityForm.submit();  
}

function doPortletEntityPreferencesView() {
  <c:url var="viewUrl" value="/ep/portletEntityPreferencesView.do">
    <c:param name="programId" value="${epPortletEntityForm.map.id}"/>
  </c:url>

  document.epPortletEntityForm.forward.value = '<c:out value="${epActionForward.map.forward}" escapeXml="false"/>';
  document.epPortletEntityForm.action = '<c:out value="${viewUrl}"/>';
  document.epPortletEntityForm.submit();
}

function checkRequiredFields(form) {
  if(form.name.value == "") {
    alert('<bean:message key='ep.alert.empty.portlet.entity.name' bundle="ep.messages"/>');
    return false;
  }
  
  if((form.status[0].checked != true) && (form.status[1].checked != true)) {
    alert('<bean:message key='ep.alert.status.not.selected' bundle="ep.messages"/>');
    return false;
  }
  
  if(form.pageType.selectedIndex==0) {
    alert('<bean:message key='ep.alert.no.page.type.selected' bundle="ep.messages"/>');
    return false;
  }
  
  var tmp_string = form.name.value;
  for (var i=0; i < tmp_string.length; i++) {
    if(tmp_string.substring(i, i+1) != " ") {
      return true;
    }
  }
  
  alert('<bean:message key='ep.alert.portlet.entity.name.all.spaces' bundle="ep.messages"/>');
  return false;
}

</script>

<c:set var="portletAppId">
<%= request.getParameter("portletAppId") %>
</c:set>
<c:set var="portletId">
<%= request.getParameter("portletId") %>
</c:set>
<c:set var="serverId">
<%= request.getParameter("serverId") %>
</c:set>

<%
  java.util.HashMap map = new java.util.HashMap();
  String pId = request.getParameter("programId");
  map.put("programId",pId);
  pageContext.setAttribute("pagetabParam",map);
%>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
      <c:if test="${epPortletEntityForm.map.id == ''}">
        <bean:message key="ep.portlet.entity.new.page.title" bundle="ep.messages"/>
      </c:if>
      <c:if test="${epPortletEntityForm.map.id != ''}">
        <bean-el:message key="ep.portlet.entity.edit.page.title" bundle="ep.messages" arg0="${epPortletEntityForm.map.name}"/>
      </c:if>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>

      <!- place body here -->

      <html-el:form action="/ep/portletEntitySave.do" onsubmit="return checkRequiredFields(this);">

      <html-el:hidden property="portletEntityId" value="${epPortletEntityForm.map.name}"/>
      <html-el:hidden property="portletAppId" value="${epPortletEntityForm.map.portletAppId}"/>
      <html-el:hidden property="portletId" value="${epPortletEntityForm.map.portletName}"/>
      <html-el:hidden property="programId" value="${epPortletEntityForm.map.id}"/>
      <html-el:hidden property="serverId" value="${epPortletEntityForm.map.serverId}"/>
      <html-el:hidden property="parentCategoryPath" value="${epPortletEntityForm.map.categoryPath}"/>
      
      <input type="hidden" name="forward" value="<c:out value="${epActionForward.map.forward}"/>">

      <div class="pageSubtitle">
        <span class="left"><bean:message key="ep.portlet.entity.information" bundle="ep.messages"/></span>
        <span class="right">&nbsp;</span>
      </div>

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="label"><bean:message key="ep.portlet.entity.name" bundle="ep.messages"/>*:</td>
        <td class="labelField"><html-el:text property="name" size="30" maxlength="80"/>
        </td>
      </tr>

      <tr>
        <td class="label"><bean:message key="ep.portlet.entity.category" bundle="ep.messages"/>:</td>
        <td class="labelField"><html-el:text property="categoryPath" size="30" maxlength="80" disabled="true"/>&nbsp;<input type="button" class="inputButton" value="<bean:message key="button.choose.portlet.entity.category" bundle="ep.messages"/>" onclick="doCategoryPopup(this.form)">
        </td>
      </tr>

      <tr>
        <td class="label"><bean:message key="ep.portlet.name" bundle="ep.messages"/>:</td>
        <td class="labelField"><c:out value="${epPortletEntityForm.map.portletName}"/>
      </tr>

      <tr>
        <td class="label"><bean:message key="ep.description" bundle="ep.messages"/>:</td>
        <td class="labelField"><c:out value="${epPortletEntityForm.map.description}"/>
      </tr>

      <tr>
        <td class="label"><bean:message key="ep.status" bundle="ep.messages"/>*:</td>
        <td class="labelField"><html-el:radio property="status" value="1"/><bean:message key="ep.status.online" bundle="ep.messages"/>&nbsp;<html-el:radio property="status" value="0"/><bean:message key="ep.status.offline" bundle="ep.messages"/>
        </td>
      </tr>

      <tr>
        <td class="label"><bean:message key="ep.portlet.page.type" bundle="ep.messages"/>*:</td>
        <td class="labelField">
            <html-el:select name="epPortletEntityForm" property="pageType" size="1">
              <html-el:option key="ep.label.select" bundle="ep.messages" value="-1"/>
              <html-el:optionsCollection name="epPortletEntityForm" property="pageTypeList"/>
            </html-el:select>
          </td>
      </table>

      <div class="pageButtonWrap" align="right">
        <input type="reset" name="resetBtn" value="<bean:message key='button.reset' bundle="ep.messages"/>" class="inputButton">
        &nbsp;&nbsp;
        <input type="button" name="cancelData" class="inputButton" value="<bean:message key='button.cancel' bundle="ep.messages"/>" onclick="doCancel()">
        <input type="submit" name="saveData" class="inputButton" value="<bean:message key='button.save' bundle="ep.messages"/>">
      </div>
      </html-el:form>
    </td>
  </tr>
</table>

